package cn.xd.security.config.wxMiniapp;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.hutool.core.util.ObjUtil;
import cn.xd.common.exception.BizException;
import cn.xd.security.config.wxMiniapp.properties.MainMiniAppProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({MainMiniAppProperties.class})
public class WxMiniAppConfig {
    @Bean("MainMiniAppService")
    public WxMaService wxMaConfig(MainMiniAppProperties wxMaProperties) {
        if (ObjUtil.isNull(wxMaProperties)) {
            throw new BizException("主小程序未配置");
        }
        WxMaService service = new WxMaServiceImpl();
        service.setWxMaConfig(wxMaProperties);
        return service;
    }
}
